#include "stdafx.h"
#include "Skybox.h"
#include "../../EdgeGraphics/TextureCube.h"
#include "../../EdgeGraphics/Model.h"
#include "../../EdgeContent/ContentManager.h"
#include "../../EdgeGraphics/Camera.h"
#include "../../EdgeGraphics/Material.h"
#include "../../EdgeGraphics/GraphicsManager.h"
#include "../../EdgeGraphics/RasterizerManager.h"
#include "../../EdgeMath/Vectors.h"

Skybox::Skybox(TextureCube* texture)
{
	model = ContentManager::GetInstance()->LoadMdl("Content/Models/cube.mdl");
	Material* mat = new Material;
	mat->textures.cube = texture;
	model->SetMaterial(mat);
	model->setShaderContainer(ContentManager::GetInstance()->LoadShaderPair("SkyboxVertexShader.cso", "SkyboxPixelShader.cso"));

	worldBuffer = new ConstantBuffer<VRAM_WORLD>(&world, { SHADER_INDEX_VERTEX_SHADER, 0 });

	memset(&world, 0, sizeof(VRAM_WORLD));
}

/*virtual*/ Skybox::~Skybox(void)
{
	delete worldBuffer;
	delete model;
}

/*virtual*/ void Skybox::Update(float dt) /*override*/
{
}

/*virtual*/ void Skybox::Draw(void) /*override*/
{
	Camera* pCamera = Camera::GetInstance();

	world.gMVP = Matricies::CreateTranslation(pCamera->getWorldPosition()) * pCamera->getView() * pCamera->getProj();
	worldBuffer->Bind();

	RasterizerManager* rm = RasterizerManager::GetInstance();

	rm->setRasterizerState(rm->states.CullNone);
	GraphicsManager::GetInstance()->Draw(model);
	rm->setRasterizerState(rm->states.CullCounterClockwise);
}